package com.deng.api.service.impl;

import com.deng.api.mapper.CloudRecruitMapper;
import com.deng.api.service.IStatictisService;
import com.deng.api.vo.StatictisVO;
import com.deng.commons.common.BaseResult;
import com.deng.commons.utils.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author by DHF
 * @Date 2022/08/2022/8/15 16:38
 * @Version 1.0
 */
@Service
public class IStatictisServiceImpl implements IStatictisService {
    @Resource
    private CloudRecruitMapper cloudRecruitMapper;
    @Override
    public BaseResult getRecruit(Long companyId) {
        //获取当前日期的上一周的时间
        List<String> titleData = DateUtils.getLastWeekDays();
        // 新增量
        List<Integer> newData = new ArrayList<>();
        // 分配量
        List<Integer> distributionData = new ArrayList<>();
        //根据时间、分配状态、companyId等条件统计即可
        titleData.forEach(date->{
            // 新增量
            Integer newCount = cloudRecruitMapper.getNew(companyId, date);
            newData.add(newCount);
            // 分配量
            Integer distributionCount = cloudRecruitMapper.getDistribution(companyId, date);
            distributionData.add(distributionCount);
        });
        return BaseResult.success(new StatictisVO(titleData,newData,distributionData));
    }

    public static void main(String[] args) {
        List<String> titleData = DateUtils.getLastWeekDays();
        System.out.println(titleData);
    }
}
